<template>
	<view>
		<view class="header" style="width: 100%;height: 300rpx;text-align: center;background: #fff;display: flex;flex-direction:column;justify-content:center">
			<text style="font-weight: bold;font-size: 60rpx;">
				{{userinfo.money}}
			</text>
			<text style="color: #7c7c7c;">
				猫猫币
			</text>
		</view>
		
		<view style="background: #efefef;width: 100%;height: 30rpx;">
			
		</view>
		
		<view style="
		background: #fff;display: flex;flex-wrap:wrap;height: 600rpx;justify-content:space-between;align-content: space-around;
		margin: 0 40rpx;
		">
			<view style="height: 150rpx;width: 30%;background: #efefef;border-radius: 20rpx;display: flex;flex-direction: column;
    justify-content: center;
    align-items: center;" v-for="(item,index) in list" @click="chilkMoney(item)" :class="showIndex==item.id?'active':''">
				<text style="">
					{{item.score}} 猫币
				</text>
				<text>
					{{item.money}}
				</text>
			</view>
			<view style="background: #efefef;width: 80%;border-radius: 30rpx;text-align: center;color: #333;margin-bottom: 30rpx;height: 150rpx;
				margin-left:10% ;
			" >
				<input type="number" style="font-size: 50rpx;transform: translateY(50%);" placeholder="自定义输入" v-model="money" @input="inputMoney">
			</view>
		</view>
		<view style="background: #efefef;width: 100%;height: 30rpx;">
			
		</view>
		<view style="padding: 30rpx;" >
			<view style="display: flex;justify-content:space-between">
				<view style="display: flex;align-items: center;">
					<image src="@/static/mao/ali.png" style="width: 40rpx;margin-right: 20rpx;" mode="widthFix"> </image>
					<text>
						Alipay
					</text>
				</view>
				<label style="float: right">
					<radio value="alipay" activeBackgroundColor="#333" :checked="pay == 'alipay'"  @click="checkPay('alipay')" />
				</label>
			</view>
			<view style="display: flex;justify-content:space-between;margin-top: 30rpx;" >
				<view style="display: flex;align-items: center;" >
					<image src="@/static/mao/wc.png" style="width: 40rpx;margin-right: 20rpx;" mode="widthFix"> </image>
					<text>
						Wechat Pay
					</text>
				</view>
				<label style="float: right">
					<radio value="wechat" activeBackgroundColor="#333" :checked="pay == 'wechat'" @click="checkPay('wechat')"/>
				</label>
			</view>
		</view>
		<view style="border-top: 4rpx solid #efefef;position: absolute;bottom: 0;height: 100rpx; width: 100%;padding: 0 30rpx;display: flex;justify-content: space-between;align-items: center">
			<text style="line-height: 100rpx;">
				应付金额：<text style="color: red;">{{paymoney}}</text>
			</text>
			
			<text style="width: 200rpx;height: 60rpx;background: #efefef;border-radius: 30rpx;line-height: 60rpx;text-align: center;" @click="paycreate">
				提交订单
			</text>
		</view>
	</view>
</template>

<script>
	import request from '@/common/request.js';
	export default {
		data() {
			return {
				spaceShow:true,
				showIndex:0,
				money:"",
				paymoney:0,
				pay:0,
				list:[
					{
						id:1,
						name:'1猫币',
						money:1
					},
					{
						id:2,
						name:'5猫币',
						money:5
					},
					{
						id:3,
						name:'10猫币',
						money:10
					},
					{
						id:4,
						name:'30猫币',
						money:30
					},
					{
						id:5,
						name:'88猫币',
						money:88
					},
					{
						id:6,
						name:'99猫币',
						money:99
					}
				],
				ali:require('@/static/mao/alipay.png'),
				wechat:require('@/static/mao/wechat.png'),
				payment:[
					
				]
			}
		},
		mounted() {
	
		},
		onLoad() {
			this.init();
		},
		methods: {
			init(){
				let user = uni.getStorageSync('userInfo');
				if(!user){
					uni.showToast({ title:'请先登录', icon: 'none' });
					setTimeout(()=>{
						uni.navigateTo({
							url:`/pages/public/login`
						})
					},1000)
					return ;
				}
				this.userinfo = user;
				let opts2 = {
					url: 'api/index/recharge',
					method: 'get'
				};
				request.httpRequest(opts2).then((res)=>{
					this.list = res.data.data.data;
				})
				
				// let opt ={
				// 	url: 'api/index/payment',
				// 	method: 'get'
				// }
				// request.httpRequest(opt).then((res)=>{
				// 	this.payment = res.data.data.data;
				// })
				
			},
			navTo(url){
				uni.navigateTo({
					url
				})
				
				return;
			},
			chilkMoney(e){
				this.showIndex = e.id;
				this.money = '';
				this.paymoney = e.money;
				console.log(this.showIndex);
			},
			inputMoney(){
				this.showIndex = 0;
				this.paymoney = this.money;
			},
			checkPay(type){
				this.pay = type;
				console.log(this.pay);
			},
			paycreate(){
				
				if(!this.paymoney){
					uni.showToast({ title:'金额不能为空', icon: 'none' });
					return ;
				}
				if(!this.pay)
				{
					uni.showToast({ title:'请选择支付方式', icon: 'none' });
					return ;
				}
				
				
				let opts2 = {
					url: 'api/index/paycreate',
					method: 'post'
				};
				let value = {
					id:this.showIndex,
					amount:this.paymoney,
					type:this.pay
				}
				request.httpTokenRequest(opts2,value).then((res)=>{
					if(res.data.code == '1'){
						let orderid = res.data.data.id;
						//发起支付
						let opts3 = {
							url: 'api/index/pay',
							method: 'get'
						};
						if(this.pay =='alipay'){
							// window.location.href = 'http://maomao.flameby.com/api/index/pay?id='+orderid;
							window.location.href = 'http://120.76.116.146:8100/api/index/pay?id='+orderid
						}
						// request.httpTokenRequest(opts3,value3).then((res)=>{
						// 	if(this.pay == 'alipay'){
						// 		uni.navigateTo({
						// 			url:'/pages'
						// 		})
						// 	}
						// })
								
					}else{
						uni.showToast({ title:res.data.msg, icon: 'none' });
						return ;
					}
				})
				
			}
			
			
		}
	}
</script>

<style lang="less">
	page{
		background: #fff;
	}
	.active{
		background: #333 !important;
		color:#fff;
	}
	
	/deep/ .uni-checkbox-input
	{
		border-radius: 50%;
		width: 30rpx;
		height: 30rpx;
	}
</style>